local skill = fk.CreateSkill{
  name = "lvshi__zhuomu",
}

Fk:loadTranslationTable{
  ["lvshi__zhuomu"] = "擢目",
  ["@[player]zhuomu-turn"] = "擢目",
  [":lvshi__zhuomu"] = "出牌阶段开始时或当你受到伤害后，你可对至多X名其他角色各造成1点伤害（X为你已损失的体力值+1）；此回合结束时，这些角色各弃置一张牌并回复1点体力。",
  ["#lvshi__zhuomu-target"] = "擢目：你可对至多%arg名角色各造成1点伤害",
  --["#lvshi__zhuomu-discard"] = "擢目：你可弃置一张牌并回复1点体力",

  ["$lvshi__zhuomu1"] = "战斗，存活，然后继续下一场战斗。",
  ["$lvshi__zhuomu2"] = "独眼，是男人的浪漫！",
}

local spec = {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skill.name) and (event == fk.Damaged or player.phase == Player.Play)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 99,
      targets = room:getOtherPlayers(player),
      skill_name = "lvshi__zhuomu",
      prompt = "#lvshi__zhuomu-target:::"..player:getLostHp() + 1,
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, to)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tos = event:getCostData(self)
    for _, p in ipairs(tos) do
      room:addTableMark(player, "@[player]zhuomu-turn", p.id)
      room:damage({
        from = player,
        to = p,
        damage = 1,
        damageType = fk.NormalDamage,
        skillName = "lvshi__zhuomu"
      })
    end
  end,
}

skill:addEffect(fk.TurnEnd, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skill.name) and #player:getTableMark("@[player]zhuomu-turn") ~= 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room:getOtherPlayers(player)) do
      if table.contains(player:getTableMark("@[player]zhuomu-turn"), p.id) and p:isWounded() and not p.dead then
        room:askToDiscard(p, {
          min_num = 1,
          max_num = 1,
          include_equip = true,
          skill_name = skill.name,
          cancelable = false,
        })
        if p:isAlive() then
          room:recover({
            who = p,
            num = 1,
            recoverBy = player,
            skillName = skill.name
          })
        end
      end
    end
  end,
})

skill:addEffect(fk.EventPhaseStart, spec)
skill:addEffect(fk.Damaged, spec)

return skill